package com.ellricky.baselib.ui.course

import android.view.View
import android.widget.AdapterView
import androidx.core.content.ContextCompat
import com.andr.common.http.callback.BaseCallback
import com.andr.common.ui.adapter.BaseRecyclerAdapter
import com.andr.common.ui.mvp.BasePresenter
import com.ellricky.baselib.BaseConstant
import com.ellricky.baselib.R
import com.ellricky.baselib.adapter.course.CourseSelectAdapter
import com.ellricky.baselib.cache.LocalCacheUtil
import com.ellricky.baselib.entity.new.WareLearn
import com.ellricky.baselib.ui.base.BaseRefreshActivity
import com.ellricky.baselib.util.EAppUtil
import com.ellricky.baselib.util.NewEBaseCallback
import com.ellricky.baselib.util.NewEListCallback

class CourseSelectActivity : BaseRefreshActivity<Void, BasePresenter<Void>, WareLearn>() {

    private val classTypeId by lazy {
        intent.extras?.getString("course_type_id") ?: ""
    }

    private val courseStateId by lazy {
        intent.extras?.getString("course_stage_id") ?: ""
    }

    private val type by lazy {
        intent.extras?.getString(BaseConstant.KEY_TYPE) ?: ""
    }

    override fun initUIView() {
        super.initUIView()
        mTvTitle.text = "课件详情"

        window.decorView.setBackgroundColor(
            ContextCompat.getColor(
                this,
                R.color.common_main_white
            )
        )
    }

    override fun initParamMap() {
        super.initParamMap()
        paramMap["action"] = "teacherCourseWarePrepareList"
        paramMap["course_type_id"] = classTypeId
        paramMap["course_stage_id"] = courseStateId
        paramMap["eid"] = LocalCacheUtil.getUid()
    }

    override fun getResponseCallback(): BaseCallback? {
        return null
    }

    override fun getResponseCallback2(): NewEBaseCallback {
        return object : NewEListCallback<WareLearn>(this) {
            override fun onSuccess(data: MutableList<WareLearn>?, msg: String?) {
                dataSource = data
                rvView.onLoadFinish(data, refresh)
            }
        }
    }

    override fun onItemClick(adapterView: AdapterView<*>?, view: View?, position: Int, l: Long) {
        super.onItemClick(adapterView, view, position, l)
        EAppUtil.jumpPageWithId(
            this,
            FileLearnDetailActivity::class.java,
            adapter.get(position).ware_id
        )
    }

    override fun getRvAdapter(): BaseRecyclerAdapter<WareLearn> {
        return CourseSelectAdapter(type)
    }

    override fun getUrlPath(): String {
        return ""
    }
}